﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class View_Admin_QuanLyNhaCungCap : System.Web.UI.Page
{
    QLNhaCC ncc = new QLNhaCC();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            GridView1.DataSource = ncc.Load_NCC();
            GridView1.DataBind();
        }
    }
    protected void btnThem_Click(object sender, EventArgs e)
    {
        ncc.Insert_NCC(txtTenncc.Text, txtdc.Text, txtDienThoai.Text);
        lblThongBao.Text = "Đã thêm thành công";
        GridView1.DataSource = ncc.Load_NCC();
        GridView1.DataBind();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        GridView1.DataSource = ncc.Load_NCC();
        GridView1.DataBind();
        GridView1.Rows[e.NewEditIndex].Cells[0].Enabled = false;
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        GridView1.DataSource = ncc.Load_NCC();
        GridView1.DataBind();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string mannc = (string)GridView1.Rows[e.RowIndex].Cells[0].Text.ToString();
        GridView1.DataSource = ncc.Delete_NCC(mannc);
        GridView1.DataSource = ncc.Load_NCC();
        GridView1.DataBind();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        TextBox mancc = (TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0];
        TextBox tencc = (TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0];
        TextBox dc = (TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0];
        TextBox dt = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0];
        GridView1.DataSource = ncc.Update_NCC(mancc.Text, tencc.Text, dc.Text, dt.Text);
        GridView1.EditIndex = -1;
        GridView1.DataSource = ncc.Load_NCC();
        GridView1.DataBind();
    }
}
